#pragma once

#include "fxcc/core/pch.h"

namespace fxcc::graph::common
{
    struct FXCC_API MSDFGeoData
    {
        struct Header
        {
            int m_NumIndices;
            int m_NumVertices;
            int m_NumTexCoords;
        };
        std::vector<glm::vec2> vertices;
        std::vector<glm::vec2> texCoords;
        std::vector<unsigned int> indices32;

        void Add(const MSDFGeoData& other)
        {
            vertices.insert(vertices.end(), other.vertices.begin(), other.vertices.end());
            texCoords.insert(texCoords.end(), other.texCoords.begin(), other.texCoords.end());
            indices32.insert(indices32.end(), other.indices32.begin(), other.indices32.end());
        };
        void Clear()
        {
            vertices = {};
            texCoords = {};
            indices32 = {};
        };
    };

    struct FXCC_API MSDFConfig
    {
        struct Altas
        {
            std::string type;
            int distanceRange;
            int distanceRangeMiddle;
            int size;
            int width;
            int height;
            std::string yOrigin;
        } altas;

        struct Metrics
        {
            int emSize;
            float lineHeight;
            float     ascender;
            float     descender;
            float     underlineY;
            float     underlineThickness;
        } metrics;

        struct Bounds {
            float left;
            float bottom;
            float right;
            float top;
        };

        struct GlyphInfo {
            int unicode;
            float advance;
            Bounds planeBounds;
            Bounds atlasBounds;
        };

        std::vector<GlyphInfo> glyphs;

        struct KerningPair
        {
            int unicode1;
            int unicode2;
            float advance;
        };

        std::vector<KerningPair> kerning;

        const GlyphInfo& getGlyph(const int unicode)
        {
            for (const auto& glyph : glyphs)
            {
                if (glyph.unicode == unicode)
                {
                    return glyph;
                }
            }
            return {};
        }

   
        const float GetKerningAdvance(const int leftUnicode, const int rightUnicode)
        {
            
            for (const auto& kp : kerning)
            {
                if (kp.unicode1 == leftUnicode && kp.unicode2 == rightUnicode)
                {
                    return kp.advance;
                }
            }
            return 0.0f;
        }
    };



}
